<template>
	<view class="tabbar">
		<u-tabbar :value="value" @change="tabbarChange" :fixed="true" :placeholder="false" :safeAreaInsetBottom="true">
			<u-tabbar-item v-for="item in list" :text="item.text">
				<image class="active-icon" slot="active-icon" :src="item.selectedIconPath"></image>
				<image class="inactive-icon" slot="inactive-icon" :src="item.iconPath"></image>
			</u-tabbar-item>
		</u-tabbar>
	</view>
</template>

<script>
	import request from '@/util/request'
	export default {
		props: {
			current: Number
		},
		data() {
			return {
				value: this.current,
				list: [],
				listMerchat: [{
						"pagePath": "pages/home/index",
						"iconPath": "../../static/icon/首页.png",
						"selectedIconPath": "../../static/icon/首页-fill.png",
						"text": "首页"
					},
					{
						"pagePath": "pages/upnew/index",
						"iconPath": "../../static/icon/发现.png",
						"selectedIconPath": "../../static/icon/发现激活.png",
						"text": "上新"
					},
					{
						"pagePath": "pages/share/show/index",
						"iconPath": "../../static/icon/朋友圈1.png",
						"selectedIconPath": "../../static/icon/朋友圈2.png",
						"text": "客作分享"
					},
					{
						"pagePath": "pages/my/index",
						"iconPath": "../../static/icon/我的.png",
						"selectedIconPath": "../../static/icon/我的-fill.png",
						"text": "我的"
					},
					{
						"pagePath": "pages/news/index",
						"iconPath": "../../static/icon/消息.png",
						"selectedIconPath": "../../static/icon/消息.png",
						"text": "消息"
					}
				],
				clientList: [{
						"pagePath": "pages/home/index",
						"iconPath": "../../static/icon/首页.png",
						"selectedIconPath": "../../static/icon/首页-fill.png",
						"text": "首页"
					},
					// {
					// 	"pagePath": "pages/upnew/index",
					// 	"iconPath": "../../static/icon/发现.png",
					// 	"selectedIconPath": "../../static/icon/发现激活.png",
					// 	"text": "上新"
					// },
					{
						"pagePath": "pages/share/show/index",
						"iconPath": "../../static/icon/朋友圈1.png",
						"selectedIconPath": "../../static/icon/朋友圈2.png",
						"text": "客作分享"
					},
					
					{
						"pagePath": "pages/booking/index",
						"iconPath": "../../static/icon/预约1.png",
						"selectedIconPath": "../../static/icon/预约2.png",
						"text": "预约"
					},
					{
						"pagePath": "pages/my/index",
						"iconPath": "../../static/icon/我的.png",
						"selectedIconPath": "../../static/icon/我的-fill.png",
						"text": "我的"
					},
					{
						"pagePath": "pages/news/index",
						"iconPath": "../../static/icon/消息.png",
						"selectedIconPath": "../../static/icon/消息.png",
						"text": "消息1"
					},
					
				],
				isLogin: false,
				isMerchant: false,
				isMerchantPhone: '',
				aboutInfo: {},
				deviceId: '' // 确保在这里定义了deviceId
			};
		},
		created() {
			this.showTabbar()
		},
		methods: {
			showTabbar() {
				this.list = this.clientList
				this.checkLoginAndSetup();
			},
			checkLoginAndSetup() {
				this.isLogin = uni.getStorageSync('isLogin') || false;
				if (this.isLogin) {
					this.getUserPhone();
				}
			},
			async getUserPhone() {
				const systemInfo = uni.getSystemInfoSync(); // 获取系统信息
				this.deviceId = systemInfo.deviceId; // 提取设备ID
				request({
					url: '/users/getUserById',
					method: 'get',
					data: {
						userId: this.deviceId
					}
				}).then(rss => {
					if (rss && rss.data) {
						this.isMerchantPhone = rss.data.phone;
						this.getPhone();
					} else {}
				}).catch(err => {
					this.handleError(err);
				});
			},
			async getPhone() {
				request({
					url: '/about/query',
					method: 'GET',
				}).then(res => {
					this.aboutInfo = res.data;
					this.isMerchant = this.isMerchantPhone === this.aboutInfo.phone; //商家
					if (this.isMerchant) {
						this.list = this.listMerchat
					}
				}).catch(err => {
					this.handleError(err);
				});
			},
			tabbarChange(e) {
				uni.switchTab({
					url: '/' + this.list[e].pagePath
				})
			},
		}
	};
</script>

<style scoped>
	.u-tabbar .tabbar-item {
		font-size: 50rpx;
	}

	.active-icon {
		width: 50rpx;
		height: 50rpx;
	}

	.inactive-icon {
		width: 50rpx;
		height: 50rpx;
	}
</style>